﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion

namespace TheSpirit
{
    class StrategyScreen : GameScreen
    {
        #region Declaration

        Texture2D StrategyTexture;
        Texture2D GameStartTexture;

        UseCard useCardPart;
        CardTree cardTreePart;

        Rectangle startRect;

        #endregion


        #region Initialize

        public StrategyScreen()
        {
            cardTreePart = new CardTree();
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            useCardPart = new UseCard(ScreenManager);
            cardTreePart.LoadContent(content);

            StrategyTexture = content.Load<Texture2D>("Strategy/Strategy");
            GameStartTexture = content.Load<Texture2D>("Strategy/GameStart");

            //위치 수정 필요
            int w = GameStartTexture.Width;
            int h = GameStartTexture.Height;
            int x = StrategyTexture.Width * 935 / 1280;
            int y = StrategyTexture.Height * 555 / 720;

            startRect = new Rectangle(x, y, w, h);
        }

        #endregion


        #region Update

        public override void HandleInput()
        {
            InputManager.ChangeMouseCursor("Normal");

            useCardPart.Update();
            cardTreePart.Update(useCardPart, ScreenManager);
            
            //게임 시작 클릭 시 필드로 넘어감
            if(Collision.IntersectPixels(InputManager.MousePosition, 
                Collision.ExtractColor(InputManager.MouseTexture()), 
                startRect, Collision.ExtractColor(GameStartTexture)))
            {
                if (InputManager.IsLeftClicked())
                {
                    ScreenManager.AddScreen(new FieldScreen(useCardPart.CardCount));
                    ExitScreen();
                    return;
                }
            }
        }

        #endregion


        #region Draw

        public override void Draw(GameTime gameTime)
        {
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            int w = viewport.Width;
            int h = viewport.Height;

            spriteBatch.Begin();
            
            spriteBatch.Draw(StrategyTexture, new Rectangle(0, 0, w, h), Color.White);
            spriteBatch.Draw(GameStartTexture, startRect, Color.White);

            useCardPart.Draw(spriteBatch);
            cardTreePart.Draw(spriteBatch);
            
            spriteBatch.End();
        }

        #endregion
    }
}
